package com.definity.toolkit.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.definity.toolkit.i18n.I18n;
import com.definity.toolkit.i18n.I18nFactory;

public class I18nServlet extends HttpServlet {

	private static final long serialVersionUID = -6537805768439869361L;

	public I18nServlet() {

	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String url = req.getPathInfo();
		String name = url.substring(1, url.indexOf("/", 1));
		String key = url.substring(url.lastIndexOf("/") + 1);
		
		I18n i18n = I18nFactory.create(name);
		
		PrintWriter out = resp.getWriter();
		out.print(i18n.tl(key));
	}
	
}
